package com.wavehi.interceptior;

import com.alibaba.druid.support.spring.stat.annotation.Stat;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.*;

import java.lang.reflect.Method;
import java.sql.Statement;
import java.util.Properties;

/**
 * @Description
 * @Author WaveHi
 * @Date 30/11/2021 下午 10:21
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 */

@Intercepts({
        @Signature(type = StatementHandler.class, method = "parameterize", args = java.sql.Statement.class)
})
public class MySecondPlugin implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        Method method = invocation.getMethod();
//        Statement statement = (Statement)invocation.getTarget();
        System.out.println("MySecondPlugin intercept! " + method.getName());
        Object proceed = invocation.proceed();
        return proceed;
    }

    @Override
    public Object plugin(Object target) {
        System.out.println("MySecondPlugin plugin!");
        Object wrap = Plugin.wrap(target, this);
        return wrap;
    }

    @Override
    public void setProperties(Properties properties) {
        System.out.println("MySecondPlugin sets property! " + properties);
    }
}
